package com.wanshi.controller;

import com.wanshi.po.Record;
import com.wanshi.po.Result;
import com.wanshi.service.RecordService;
import com.wanshi.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpSession;
import java.util.UUID;

@SuppressWarnings("all")
@Controller
@RequestMapping("dati")
public class DatiPrint2Controller {

    @Autowired
    private RecordService recordService;

    private static String lineSeparator = System.getProperty("line.separator", "\n");

    public String yanghui(int n) {
        StringBuffer buffer = new StringBuffer();
        int[][] arr = new int[n][];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = new int[i + 1];
        }
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                if (j == 0 || i == j) {
                    arr[i][j] = 1;
                } else {
                    arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1];
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                buffer.append(arr[i][j] + ",");
            }
            buffer.append(""+lineSeparator);
        }
        return buffer.toString();
    }

    @RequestMapping(value = "/test80")
    @ResponseBody
    public Result test80(HttpSession session, int id, String content, String method) {
        if (TextUtil.kong(content)) return new Result(Constants.ERROR);
        Record record = RequestUtils.getRecord(session, id, content);
        DaTiUtils daTiUtils = new DaTiUtils<>();
        boolean flag = true;
        String uuid = UUID.randomUUID().toString().replace("-", "");
        try {
            int x = 3;
            String result = daTiUtils.writeContent2(uuid, content, method, new Object[]{x});
            flag = result.equals(yanghui(3));
            if (!flag) {
                return RequestUtils.getResult(recordService, record, flag);
            }
            x = 7;
            result = daTiUtils.writeContent2(uuid, content, method, new Object[]{x});
            flag = result.equals(yanghui(7));
        } catch (Exception e) {
            flag = false;
        } finally {
          ThreadPoolUtils.pool.execute(new AsynOprDatabaseUtil(recordService, record, flag,uuid));
            return RequestUtils.getResult(recordService, record, flag);
        }
    }
}
